package com.sitechasia.webx.components.xtable.customertag;

import org.apache.commons.lang.StringUtils;
import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.view.html.ColumnBuilder;
import org.extremecomponents.util.HtmlBuilder;

public class CeColumnBuilder extends ColumnBuilder {
	private HtmlBuilder html = null;
	private Column column = null;
	public CeColumnBuilder(Column column) {
		super(column);
		html = getHtmlBuilder();
		this.column = column;
	}

	public CeColumnBuilder(HtmlBuilder html, Column column){
		super(html,column);
	}

	@Override
	public void tdStart() {
		html.td(2);
		id();
		nowrap();
		align();
        styleClass();
        style();
        width();
        name();
        onClick();
        onDblClick();
        onContextMenu();
        title();
        html.close();
	}

	public void id(){
		String id = column.getAttributeAsString("id");
		html.id(id);
	}
	public void align(){
		String align = column.getAttributeAsString("align");
		html.align(align);
	}
	public void name(){
		String name = column.getAttributeAsString("name");
		html.name(name);
	}
	public void onClick(){
		String onClick = column.getAttributeAsString("onClick");
		html.onclick(onClick);
	}

	public void onDblClick(){
		String onDblClick = column.getAttributeAsString("onDblClick");
		if(StringUtils.isNotBlank(onDblClick))
			html.append(" onDblClick=\"" + onDblClick + "\"");
	}

	public void onContextMenu(){
		String onContextMenu = column.getAttributeAsString("onContextMenu");
		if(StringUtils.isNotBlank(onContextMenu)){
			html.append(" onContextMenu=\"" + onContextMenu + "\"");
		}
	}
	public void nowrap(){
		html.append(" nowrap ");
	}
	public void title(){
		String showTitle = (String)column.getAttribute("showTitle");
		if(showTitle != null  && "true".equalsIgnoreCase(showTitle))
			html.append(" title=\"" + column.getValueAsString().trim() + "\"");
	}
}
